//
//  ViewController.m
//  24-keep secret
//
//  Created by Snow on 16/8/16.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "NSString+GXMD5.h"
#import "NetWorking.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *AddSecrt;
@property (weak, nonatomic) IBOutlet UIButton *cancelSecrt;
@property (weak, nonatomic) IBOutlet UITextField *textOfAddSecrt;
@property (weak, nonatomic) IBOutlet UITextField *textOfCancelSecrt;
@property (weak, nonatomic) IBOutlet UIButton *buttonOfMD5;
@property (nonatomic, copy) NSString *addUrlString;
@property (nonatomic, copy) NSString *cancelUrlString;
@property (nonatomic, copy) NSString *cancelstringPar;
@property (nonatomic, copy) NSString *addstringPar;
@end
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _addUrlString = @"http://tool.zzblo.com/api/md5/encrypt";
    _cancelUrlString = @"http://tool.zzblo.com/api/md5/decrypt";
    _addstringPar = @"text=";
    _cancelstringPar = @"secret=";
    
}
- (IBAction)addSecret:(id)sender {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *parameters = [_addstringPar stringByAppendingFormat:@"%@", _textOfAddSecrt.text];
    [manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        return parameters;
    }];
    [manager POST:_addUrlString parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        _textOfCancelSecrt.text = responseObject[@"secret16"];
        _textOfAddSecrt.text = @"";
        NSLog(@"加密成功");
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"加密失败");
    }];
}
- (IBAction)cancelSecret:(id)sender {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *parameters = [_cancelstringPar stringByAppendingFormat:@"%@", _textOfCancelSecrt.text];
    [manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        return parameters;
    }];
    [manager POST:_cancelUrlString parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        _textOfAddSecrt.text = responseObject[@"text"];
        NSLog(@"解密成功");
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"解密失败");
    }];
}
- (IBAction)pressonMD5:(id)sender {
    _textOfCancelSecrt.text = [_textOfAddSecrt.text stringWith16BitMD5Lower];
    _textOfAddSecrt.text = @"";

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
